import { BasicColumn, FormSchema } from "/@/components/Table"
import { render } from "/@/utils/common/renderUtils"
import { DescItem } from "/@/components/Description/index"
import { useI18n } from "/@/hooks/web/useI18n"
import { UploadBizType } from "/@/enums/uploadEnum"
import { listDataGroupTree } from "/@/api/infra/dataGroup"
import { DataGroupBizType } from "/@/components/BizDataGroup/index"
const { t } = useI18n("")

export const columns: BasicColumn[] = [
  {
    title: t("菜单名称"),
    dataIndex: "title",
    align: "left",
    width: 100,
  },
  {
    title: t("菜单组"),
    dataIndex: "groupName",
    width: 100,
  },
  {
    title: t("图标"),
    dataIndex: "imageUrl",
    width: 80,
    customRender: ({ text }) => {
      return render.renderImagePreview({
        imageList: [{ src: text, width: 80 }],
      })
    },
  },
  {
    title: t("排序"),
    helpMessage: "越小越靠前",
    dataIndex: "sortNo",
    width: 100,
  },
  {
    title: t("链接"),
    dataIndex: "pageUrl",
    width: 100,
  },
  // {
  //   title: t('标签'),
  //   dataIndex: 'sysTag',
  //   width: 100,
  // },
  {
    title: t("显示位置"),
    dataIndex: "displayPositionText",
    customRender: ({ text }) => {
      let color = "cyan"
      if (text === "1") {
        color = "green"
      }
      return render.renderTag(text, color)
    },
    width: 80,
  },
  {
    title: t("状态"),
    dataIndex: "status",
    customRender: ({ text }) => {
      let color = "warning"
      if (text === "1") {
        color = "green"
      }
      return render.renderTag(render.renderDict(text, "show_status"), color)
    },
    width: 64,
  },
  {
    title: t("创建时间"),
    dataIndex: "createdAt",
    width: 150,
  },
  // {
  //   title: t('更新时间'),
  //   dataIndex: 'updatedAt',
  //   width: 150,
  // },
]

export const searchFormSchema: FormSchema[] = [
  {
    label: t("菜单名称"),
    field: "title",
    component: "Input",
  },
  {
    label: "显示位置",
    field: "displayPosition",
    component: "JDictSelectTag",
    componentProps: {
      placeholder: "请选择",
      allowClear: true,
      dictType: "menu_display_position",
    },
  },
]

export const inputFormSchemas: FormSchema[] = [
  {
    label: "",
    field: "id",
    component: "Input",
    show: false,
  },
  {
    label: "链接名称",
    field: "name",
    component: "Input",
    show: false,
  },
  {
    label: t("菜单名称"),
    field: "title",
    component: "Input",
    required: true,
    componentProps: {
      maxlength: 30,
    },
  },
  {
    label: t("图标"),
    field: "imageUrl",
    component: "MySelectMaterial",
    componentProps: {
      fileMax: 1,
      fieldName: "url",
      bizType: UploadBizType.GENERAL_IMAGE,
    },
  },
  {
    label: t("排序"),
    helpMessage: "越小越靠前",
    field: "sortNo",
    defaultValue: 0,
    component: "InputNumber",
    componentProps: {
      maxlength: 10,
    },
  },
  {
    label: t("页面地址"),
    field: "pageUrl",
    component: "Input",
    slot: "pageUrl",
  },
  // {
  //   label: t('链接名称'),
  //   field: 'name',
  //   component: 'Input',
  //   componentProps: {
  //     maxlength: 120,
  //   },
  // },

  {
    label: "显示位置",
    field: "displayPosition",
    required: true,
    component: "JDictSelectTag",
    defaultValue: "1",
    componentProps: {
      type: "radio",
      dictType: "menu_display_position",
    },
  },
  {
    label: "菜单组",
    field: "groupCode",
    required: true,
    component: "ApiSelect",
    componentProps: {
      api: listDataGroupTree,
      params: {
        bizType: DataGroupBizType.MOBILE_MENU,
      },
      optionFilterProp: "label",
      showSearch: true,
      labelField: "name",
      valueField: "code",
      dropdownStyle: { maxHeight: "16vh", overflow: "auto" },
    },
  },
  {
    label: "状态",
    field: "status",
    required: true,
    component: "JDictSelectTag",
    defaultValue: "1",
    componentProps: {
      type: "radio",
      dictType: "show_status",
    },
  },
]

export const formDetailSchema: DescItem[] = [
  {
    label: t("菜单名称"),
    field: "title",
  },
  {
    label: t("菜单组"),
    field: "groupName",
  },
  {
    label: t("图标"),
    field: "imageUrl",
    render: (curVal, data) => {
      return render.renderImagePreview({
        imageList: [{ src: curVal, width: 80 }],
      })
    },
  },
  {
    label: t("链接地址"),
    field: "pageUrl",
  },
  {
    label: t("链接名称"),
    field: "name",
  },
  {
    label: t("排序"),
    field: "sortNo",
  },
  {
    field: "status",
    label: t("状态"),
    render: (curVal, data) => {
      let color = "warning"
      if (curVal === "1") {
        color = "green"
      }
      return render.renderTag(render.renderDict(curVal, "show_status"), color)
    },
  },
  {
    label: t("创建时间"),
    field: "createdAt",
  },
  {
    label: t("更新时间"),
    field: "updatedAt",
  },
  {
    label: t("创建者"),
    field: "createdBy",
  },
  {
    label: t("更新者"),
    field: "updatedBy",
  },
]
